package models;

import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import play.data.format.Formats;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;

@Entity
public class Proposition extends Model {

	@Id
	public Long id;
	@Required
	public String libelle;
	@Formats.DateTime(pattern = "yyyy-MM-dd")
	public Date date;

	@ManyToOne
	public Utilisateur utilisateur;

	@ManyToOne
	public Etat etat;

	public static Finder<Long, Proposition> find = new Finder<Long, Proposition>(
			Long.class, Proposition.class);

	public static Proposition findFirst() {
		return find.orderBy().desc("id").findList().listIterator().next();
	}

	public static Proposition findbyId(Long id) {
		return find.byId(id);
	}

	public void changerEtat(int new_etat) {
		etat = Etat.findById((long) new_etat);
		update();
	}

}
